﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapWBDAT(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWBDAT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWBDAT(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWBDAT(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertWBDAT(dwLocal);
            }
            UpdateWBDAT(dwLocal);
        }
        public void InsertWBDAT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "INSERT INTO WBDAT(WBMANDANT, WBRWKRS, WBRWLFD, WBLESTKNR, WBKUNDNR, WBWERK, WBABT, WBWAKZ, WBART, WBVAR, WBDESS, WBCOLORIT, WBFARBE, WBBESCHICH, WBZUSTAND, WBLIEFSCHNR, WBLIEFDAT, WBWEBER, WBABS, WBEINDAT, WBEINLO, WBKDPART, WBSPSTA, WBSPGRD, WBSTK, WBMTR, WBGEBANZ, WBKGBRUT, WBKGNET, WBKGTARA, WBMEWE, WBSTKK, WBMTRK, WBGEBANZK, WBKGNETK, WBRWAUFMSL, WBGEBART, WBBRT, WBGRQM, WBGRLFD, WBFDDIK, WBFDDIS, WBPRUEF, WBSCHLIGR1, WBSCHLIGR2, WBSCHLIGR3, WBSCHLIGR4, WBSCHLIGR5, WBSCHLINR1, WBSCHLINR2, WBSCHLINR3, WBSCHLINR4, WBSCHLINR5, WBFILLER1, WBSCHLIKZ, WBMATERIAL, WBKRITISCH, WBKDSTK, WBVERSRUE, WBKANTE, WBENTKZ, WBBESTKZ, WBBESTKRS, WBBESTLFD, WBBESTPOS, WBKOKRS, WBKOLFD, WBNETMTR, WBFERTKZ, WBREDAT, WBRENR, WBREWERT, WBSTAPO, WBPLPREIS, WBEINVKZ, WBMATPRF, WBSPEDF, WBSPEDV, WBSPEDZ, WBURRENR, WBURLAND, WBBUSIMODE, WBDRVERT, WBCBOOKNO, WBCITEMNO, WBZOLLST, WBFILLER2, WBAENDZL, WBAENDBEN, WBAENDDAT, WBNEUBEN, WBNEUDAT)"
                                        + " VALUES (:WBMANDANT, :WBRWKRS, :WBRWLFD, '1111', '00000000', '   ', '   ', 'F', 'PV912102            ', '12', '          ', '          ', 'RD01      ', 'F01       ', '    ', 'DL2840    ', 20100917, '        ', '                              ', 20100917, '01', 'LT2840A   ', '  ', '  ', 10, 120000, 1, 0, 47400, 0, '   ', 10, 120000, 0, 47400, '  ', 'TC  ', 15800, 250, 395, 0, 0, 'SUNLV   ', ' ', ' ', ' ', ' ', ' ', '   ', '   ', '   ', '   ', '   ', ' ', 'J', 'J', ' ', 'N', ' ', '  ', ' ', ' ', '  ', '      ', '   ', '  ', '      ', 120000, 'Z', 0, '          ', 0, '  ', 0, 'E', ' ', ' ', ' ', ' ', '          ', 'CN ', '   ', '                    ', '               ', 0, '      ', '                                              ', 12, 'SUNLV   ', 20100917, 'SUNLV   ', 20100917)";
            or1.Parameters.Add("WBMANDANT", OracleType.NVarChar).Value = dwData["WBMANDANT"].ToString();
            or1.Parameters.Add("WBRWKRS", OracleType.NVarChar).Value = dwData["WBRWKRS"].ToString();
            or1.Parameters.Add("WBRWLFD", OracleType.NVarChar).Value = dwData["WBRWLFD"].ToString();
            Connect2Proxy(or1);
        }
        public DataSet QueryWBDAT(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM WBDAT WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM WBDAT WHERE WBMANDANT=:WBMANDANT "
                    + "AND WBRWKRS=:WBRWKRS AND WBRWLFD=:WBRWLFD ";
                    or1.Parameters.Add("WBMANDANT", OracleType.NVarChar).Value = dwData["WBMANDANT"].ToString();
                    or1.Parameters.Add("WBRWKRS", OracleType.NVarChar).Value = dwData["WBRWKRS"].ToString();
                    or1.Parameters.Add("WBRWLFD", OracleType.NVarChar).Value = dwData["WBRWLFD"].ToString();
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "WBDAT";
            Return = Result;
            return Return;
        }
        public void UpdateWBDAT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            DataSet result = new DataSet();
            or1 = OracleDB.CreateCommand();
            #region====Command====
            or1.CommandText = "UPDATE WBDAT SET "
                + "WBMANDANT=:WBMANDANT,"
                + "WBRWKRS=:WBRWKRS,"
                + "WBRWLFD=:WBRWLFD,"
                + "WBLESTKNR=:WBLESTKNR,"
                + "WBKUNDNR=:WBKUNDNR,"
                + "WBWERK=:WBWERK,"
                + "WBABT=:WBABT,"
                + "WBWAKZ=:WBWAKZ,"
                + "WBART=:WBART,"
                + "WBVAR=:WBVAR,"
                + "WBDESS=:WBDESS,"
                + "WBCOLORIT=:WBCOLORIT,"
                + "WBFARBE=:WBFARBE,"
                + "WBBESCHICH=:WBBESCHICH,"
                + "WBZUSTAND=:WBZUSTAND,"
                + "WBLIEFSCHNR=:WBLIEFSCHNR,"
                + "WBLIEFDAT=:WBLIEFDAT,"
                + "WBWEBER=:WBWEBER,"
                + "WBABS=:WBABS,"
                + "WBEINDAT=:WBEINDAT,"
                + "WBEINLO=:WBEINLO,"
                + "WBKDPART=:WBKDPART,"
                + "WBSPSTA=:WBSPSTA,"
                + "WBSPGRD=:WBSPGRD,"
                + "WBSTK=:WBSTK,"
                + "WBMTR=:WBMTR,"
                + "WBGEBANZ=:WBGEBANZ,"
                + "WBKGBRUT=:WBKGBRUT,"
                + "WBKGNET=:WBKGNET,"
                + "WBKGTARA=:WBKGTARA,"
                + "WBMEWE=:WBMEWE,"
                + "WBSTKK=:WBSTKK,"
                + "WBMTRK=:WBMTRK,"
                + "WBGEBANZK=:WBGEBANZK,"
                + "WBKGNETK=:WBKGNETK,"
                + "WBRWAUFMSL=:WBRWAUFMSL,"
                + "WBGEBART=:WBGEBART,"
                + "WBBRT=:WBBRT,"
                + "WBGRQM=:WBGRQM,"
                + "WBGRLFD=:WBGRLFD,"
                + "WBFDDIK=:WBFDDIK,"
                + "WBFDDIS=:WBFDDIS,"
                + "WBPRUEF=:WBPRUEF,"
                + "WBSCHLIGR1=:WBSCHLIGR1,"
                + "WBSCHLIGR2=:WBSCHLIGR2,"
                + "WBSCHLIGR3=:WBSCHLIGR3,"
                + "WBSCHLIGR4=:WBSCHLIGR4,"
                + "WBSCHLIGR5=:WBSCHLIGR5,"
                + "WBSCHLINR1=:WBSCHLINR1,"
                + "WBSCHLINR2=:WBSCHLINR2,"
                + "WBSCHLINR3=:WBSCHLINR3,"
                + "WBSCHLINR4=:WBSCHLINR4,"
                + "WBSCHLINR5=:WBSCHLINR5,"
                + "WBFILLER1=:WBFILLER1,"
                + "WBSCHLIKZ=:WBSCHLIKZ,"
                + "WBMATERIAL=:WBMATERIAL,"
                + "WBKRITISCH=:WBKRITISCH,"
                + "WBKDSTK=:WBKDSTK,"
                + "WBVERSRUE=:WBVERSRUE,"
                + "WBKANTE=:WBKANTE,"
                + "WBENTKZ=:WBENTKZ,"
                + "WBBESTKZ=:WBBESTKZ,"
                + "WBBESTKRS=:WBBESTKRS,"
                + "WBBESTLFD=:WBBESTLFD,"
                + "WBBESTPOS=:WBBESTPOS,"
                + "WBKOKRS=:WBKOKRS,"
                + "WBKOLFD=:WBKOLFD,"
                + "WBNETMTR=:WBNETMTR,"
                + "WBFERTKZ=:WBFERTKZ,"
                + "WBREDAT=:WBREDAT,"
                + "WBRENR=:WBRENR,"
                + "WBREWERT=:WBREWERT,"
                + "WBSTAPO=:WBSTAPO,"
                + "WBPLPREIS=:WBPLPREIS,"
                + "WBEINVKZ=:WBEINVKZ,"
                + "WBMATPRF=:WBMATPRF,"
                + "WBSPEDF=:WBSPEDF,"
                + "WBSPEDV=:WBSPEDV,"
                + "WBSPEDZ=:WBSPEDZ,"
                + "WBURRENR=:WBURRENR,"
                + "WBURLAND=:WBURLAND,"
                + "WBBUSIMODE=:WBBUSIMODE,"
                + "WBDRVERT=:WBDRVERT,"
                + "WBCBOOKNO=:WBCBOOKNO,"
                + "WBCITEMNO=:WBCITEMNO,"
                + "WBZOLLST=:WBZOLLST,"
                + "WBFILLER2=:WBFILLER2,"
                + "WBAENDZL=:WBAENDZL,"
                + "WBAENDBEN=:WBAENDBEN,"
                + "WBAENDDAT=:WBAENDDAT,"
                + "WBNEUBEN=:WBNEUBEN,"
                + "WBNEUDAT=:WBNEUDAT"
               + " WHERE  "
               + "  WBMANDANT=:WBMANDANT AND WBRWKRS=:WBRWKRS AND WBRWLFD=:WBRWLFD";
            #endregion

            #region====Parameters====
            or1.Parameters.Add("WBMANDANT", OracleType.NVarChar).Value = dwData["WBMANDANT"].ToString();
            or1.Parameters.Add("WBRWKRS", OracleType.NVarChar).Value = dwData["WBRWKRS"].ToString();
            or1.Parameters.Add("WBRWLFD", OracleType.NVarChar).Value = dwData["WBRWLFD"].ToString();
            or1.Parameters.Add("WBLESTKNR", OracleType.NVarChar).Value = dwData["WBLESTKNR"].ToString();
            or1.Parameters.Add("WBKUNDNR", OracleType.NVarChar).Value = dwData["WBKUNDNR"].ToString();
            or1.Parameters.Add("WBWERK", OracleType.NVarChar).Value = dwData["WBWERK"].ToString();
            or1.Parameters.Add("WBABT", OracleType.NVarChar).Value = dwData["WBABT"].ToString();
            or1.Parameters.Add("WBWAKZ", OracleType.NVarChar).Value = dwData["WBWAKZ"].ToString();
            or1.Parameters.Add("WBART", OracleType.NVarChar).Value = dwData["WBART"].ToString();
            or1.Parameters.Add("WBVAR", OracleType.NVarChar).Value = dwData["WBVAR"].ToString();
            or1.Parameters.Add("WBDESS", OracleType.NVarChar).Value = dwData["WBDESS"].ToString();
            or1.Parameters.Add("WBCOLORIT", OracleType.NVarChar).Value = dwData["WBCOLORIT"].ToString();
            or1.Parameters.Add("WBFARBE", OracleType.NVarChar).Value = dwData["WBFARBE"].ToString();
            or1.Parameters.Add("WBBESCHICH", OracleType.NVarChar).Value = dwData["WBBESCHICH"].ToString();
            or1.Parameters.Add("WBZUSTAND", OracleType.NVarChar).Value = dwData["WBZUSTAND"].ToString();
            or1.Parameters.Add("WBLIEFSCHNR", OracleType.NVarChar).Value = dwData["WBLIEFSCHNR"].ToString();
            or1.Parameters.Add("WBLIEFDAT", OracleType.NVarChar).Value = dwData["WBLIEFDAT"].ToString();
            or1.Parameters.Add("WBWEBER", OracleType.NVarChar).Value = dwData["WBWEBER"].ToString();
            or1.Parameters.Add("WBABS", OracleType.NVarChar).Value = dwData["WBABS"].ToString();
            or1.Parameters.Add("WBEINDAT", OracleType.NVarChar).Value = dwData["WBEINDAT"].ToString();
            or1.Parameters.Add("WBEINLO", OracleType.NVarChar).Value = dwData["WBEINLO"].ToString();
            or1.Parameters.Add("WBKDPART", OracleType.NVarChar).Value = dwData["WBKDPART"].ToString();
            or1.Parameters.Add("WBSPSTA", OracleType.NVarChar).Value = dwData["WBSPSTA"].ToString();
            or1.Parameters.Add("WBSPGRD", OracleType.NVarChar).Value = dwData["WBSPGRD"].ToString();
            or1.Parameters.Add("WBSTK", OracleType.NVarChar).Value = dwData["WBSTK"].ToString();
            or1.Parameters.Add("WBMTR", OracleType.NVarChar).Value = dwData["WBMTR"].ToString();
            or1.Parameters.Add("WBGEBANZ", OracleType.NVarChar).Value = dwData["WBGEBANZ"].ToString();
            or1.Parameters.Add("WBKGBRUT", OracleType.NVarChar).Value = dwData["WBKGBRUT"].ToString();
            or1.Parameters.Add("WBKGNET", OracleType.NVarChar).Value = dwData["WBKGNET"].ToString();
            or1.Parameters.Add("WBKGTARA", OracleType.NVarChar).Value = dwData["WBKGTARA"].ToString();
            or1.Parameters.Add("WBMEWE", OracleType.NVarChar).Value = dwData["WBMEWE"].ToString();
            or1.Parameters.Add("WBSTKK", OracleType.NVarChar).Value = dwData["WBSTKK"].ToString();
            or1.Parameters.Add("WBMTRK", OracleType.NVarChar).Value = dwData["WBMTRK"].ToString();
            or1.Parameters.Add("WBGEBANZK", OracleType.NVarChar).Value = dwData["WBGEBANZK"].ToString();
            or1.Parameters.Add("WBKGNETK", OracleType.NVarChar).Value = dwData["WBKGNETK"].ToString();
            or1.Parameters.Add("WBRWAUFMSL", OracleType.NVarChar).Value = dwData["WBRWAUFMSL"].ToString();
            or1.Parameters.Add("WBGEBART", OracleType.NVarChar).Value = dwData["WBGEBART"].ToString();
            or1.Parameters.Add("WBBRT", OracleType.NVarChar).Value = dwData["WBBRT"].ToString();
            or1.Parameters.Add("WBGRQM", OracleType.NVarChar).Value = dwData["WBGRQM"].ToString();
            or1.Parameters.Add("WBGRLFD", OracleType.NVarChar).Value = dwData["WBGRLFD"].ToString();
            or1.Parameters.Add("WBFDDIK", OracleType.NVarChar).Value = dwData["WBFDDIK"].ToString();
            or1.Parameters.Add("WBFDDIS", OracleType.NVarChar).Value = dwData["WBFDDIS"].ToString();
            or1.Parameters.Add("WBPRUEF", OracleType.NVarChar).Value = dwData["WBPRUEF"].ToString();
            or1.Parameters.Add("WBSCHLIGR1", OracleType.NVarChar).Value = dwData["WBSCHLIGR1"].ToString();
            or1.Parameters.Add("WBSCHLIGR2", OracleType.NVarChar).Value = dwData["WBSCHLIGR2"].ToString();
            or1.Parameters.Add("WBSCHLIGR3", OracleType.NVarChar).Value = dwData["WBSCHLIGR3"].ToString();
            or1.Parameters.Add("WBSCHLIGR4", OracleType.NVarChar).Value = dwData["WBSCHLIGR4"].ToString();
            or1.Parameters.Add("WBSCHLIGR5", OracleType.NVarChar).Value = dwData["WBSCHLIGR5"].ToString();
            or1.Parameters.Add("WBSCHLINR1", OracleType.NVarChar).Value = dwData["WBSCHLINR1"].ToString();
            or1.Parameters.Add("WBSCHLINR2", OracleType.NVarChar).Value = dwData["WBSCHLINR2"].ToString();
            or1.Parameters.Add("WBSCHLINR3", OracleType.NVarChar).Value = dwData["WBSCHLINR3"].ToString();
            or1.Parameters.Add("WBSCHLINR4", OracleType.NVarChar).Value = dwData["WBSCHLINR4"].ToString();
            or1.Parameters.Add("WBSCHLINR5", OracleType.NVarChar).Value = dwData["WBSCHLINR5"].ToString();
            or1.Parameters.Add("WBFILLER1", OracleType.NVarChar).Value = dwData["WBFILLER1"].ToString();
            or1.Parameters.Add("WBSCHLIKZ", OracleType.NVarChar).Value = dwData["WBSCHLIKZ"].ToString();
            or1.Parameters.Add("WBMATERIAL", OracleType.NVarChar).Value = dwData["WBMATERIAL"].ToString();
            or1.Parameters.Add("WBKRITISCH", OracleType.NVarChar).Value = dwData["WBKRITISCH"].ToString();
            or1.Parameters.Add("WBKDSTK", OracleType.NVarChar).Value = dwData["WBKDSTK"].ToString();
            or1.Parameters.Add("WBVERSRUE", OracleType.NVarChar).Value = dwData["WBVERSRUE"].ToString();
            or1.Parameters.Add("WBKANTE", OracleType.NVarChar).Value = dwData["WBKANTE"].ToString();
            or1.Parameters.Add("WBENTKZ", OracleType.NVarChar).Value = dwData["WBENTKZ"].ToString();
            or1.Parameters.Add("WBBESTKZ", OracleType.NVarChar).Value = dwData["WBBESTKZ"].ToString();
            or1.Parameters.Add("WBBESTKRS", OracleType.NVarChar).Value = dwData["WBBESTKRS"].ToString();
            or1.Parameters.Add("WBBESTLFD", OracleType.NVarChar).Value = dwData["WBBESTLFD"].ToString();
            or1.Parameters.Add("WBBESTPOS", OracleType.NVarChar).Value = dwData["WBBESTPOS"].ToString();
            or1.Parameters.Add("WBKOKRS", OracleType.NVarChar).Value = dwData["WBKOKRS"].ToString();
            or1.Parameters.Add("WBKOLFD", OracleType.NVarChar).Value = dwData["WBKOLFD"].ToString();
            or1.Parameters.Add("WBNETMTR", OracleType.NVarChar).Value = dwData["WBNETMTR"].ToString();
            or1.Parameters.Add("WBFERTKZ", OracleType.NVarChar).Value = dwData["WBFERTKZ"].ToString();
            or1.Parameters.Add("WBREDAT", OracleType.NVarChar).Value = dwData["WBREDAT"].ToString();
            or1.Parameters.Add("WBRENR", OracleType.NVarChar).Value = dwData["WBRENR"].ToString();
            or1.Parameters.Add("WBREWERT", OracleType.NVarChar).Value = dwData["WBREWERT"].ToString();
            or1.Parameters.Add("WBSTAPO", OracleType.NVarChar).Value = dwData["WBSTAPO"].ToString();
            or1.Parameters.Add("WBPLPREIS", OracleType.NVarChar).Value = dwData["WBPLPREIS"].ToString();
            or1.Parameters.Add("WBEINVKZ", OracleType.NVarChar).Value = dwData["WBEINVKZ"].ToString();
            or1.Parameters.Add("WBMATPRF", OracleType.NVarChar).Value = dwData["WBMATPRF"].ToString();
            or1.Parameters.Add("WBSPEDF", OracleType.NVarChar).Value = dwData["WBSPEDF"].ToString();
            or1.Parameters.Add("WBSPEDV", OracleType.NVarChar).Value = dwData["WBSPEDV"].ToString();
            or1.Parameters.Add("WBSPEDZ", OracleType.NVarChar).Value = dwData["WBSPEDZ"].ToString();
            or1.Parameters.Add("WBURRENR", OracleType.NVarChar).Value = dwData["WBURRENR"].ToString();
            or1.Parameters.Add("WBURLAND", OracleType.NVarChar).Value = dwData["WBURLAND"].ToString();
            or1.Parameters.Add("WBBUSIMODE", OracleType.NVarChar).Value = dwData["WBBUSIMODE"].ToString();
            or1.Parameters.Add("WBDRVERT", OracleType.NVarChar).Value = dwData["WBDRVERT"].ToString();
            or1.Parameters.Add("WBCBOOKNO", OracleType.NVarChar).Value = dwData["WBCBOOKNO"].ToString();
            or1.Parameters.Add("WBCITEMNO", OracleType.NVarChar).Value = dwData["WBCITEMNO"].ToString();
            or1.Parameters.Add("WBZOLLST", OracleType.NVarChar).Value = dwData["WBZOLLST"].ToString();
            or1.Parameters.Add("WBFILLER2", OracleType.NVarChar).Value = dwData["WBFILLER2"].ToString();
            or1.Parameters.Add("WBAENDZL", OracleType.NVarChar).Value = dwData["WBAENDZL"].ToString();
            or1.Parameters.Add("WBAENDBEN", OracleType.NVarChar).Value = dwData["WBAENDBEN"].ToString();
            or1.Parameters.Add("WBAENDDAT", OracleType.NVarChar).Value = dwData["WBAENDDAT"].ToString();
            or1.Parameters.Add("WBNEUBEN", OracleType.NVarChar).Value = dwData["WBNEUBEN"].ToString();
            or1.Parameters.Add("WBNEUDAT", OracleType.NVarChar).Value = dwData["WBNEUDAT"].ToString();
            #endregion

            Connect2Proxy(or1);
        }
    }
}
